import { stringify } from 'qs';
import request from '@/utils/request';

export async function query(params) {
  const { url, ...paramsOpt } = params;
  console.log(paramsOpt);
  return request(`${url}?${stringify(paramsOpt)}`, {
    method: 'GET',
  });
}
export async function add(params) {
  const { url, ...paramsOpt } = params;
  return request.post(url, {
    method: 'POST',
    data: paramsOpt,
  });
}
export async function edit(params) {
  const { url, ...paramsOpt } = params;
  return request.put(`${url}/${paramsOpt.id || paramsOpt.sid}`, {
    method: 'PUT',
    data: paramsOpt,
  });
}
export async function remove(params) {
  const { url, ...paramsOpt } = params;
  return request.delete(`${url}/${paramsOpt.id || paramsOpt.sid}`, {
    method: 'DELETE',
  });
}
export async function queryGet(params) {
  const { url, ...paramsOpt } = params;
  return request(`${url}?${stringify(paramsOpt)}`, {
    method: 'GET',
  });
}
export async function queryOne(params) {
  const { url, ...paramsOpt } = params;
  return request(`${url}/${paramsOpt.id || paramsOpt.sid}`, {
    method: 'GET',
  });
}




